﻿using Hangfire.Common;
using Hangfire.States;
using Mt.Site.Core.Navigations.Exceptions;

namespace Mt.Site.Web.Filters
{
    public class CheckJobExceptionAttribute : JobFilterAttribute, IElectStateFilter
    //, IClientFilter, IServerFilter, , IApplyStateFilter
    {
        //private static readonly ILog Logger = LogProvider.GetCurrentClassLogger();

        public void OnStateElection(ElectStateContext context)
        {
            var failedState = context.CandidateState as FailedState;
            if (failedState != null)
            {
                if (failedState.Exception is MenuItemNotFoundException)
                {
                    context.CandidateState = new DeletedState { Reason = "MenuItemNotFoundException" };
                }
            }
        }
    }
}
